package com.wfm.niuke.mianshi;

import java.io.File;
import java.util.Arrays;
import java.util.List;
import org.junit.Test;

public class CountFileDir {
    int dirNum;
    int fileNum;
    public void countFileDir(String name){
        dfs(name);
    }
    void dfs(String name){
        File[] files = listDirFile(name);
        for (int i = 0; i < files.length; i++) {
            if(files[i].isDirectory()){
                dirNum++;
                String name1 = files[i].getAbsolutePath();
                dfs(name1);
            }
            if(files[i].isFile()){
                fileNum++;
            }
        }
    }

    private File[] listDirFile(String name) {
        File file = new File(name);
        File[] files = file.listFiles();
        return files;
    }

    @Test
    public void test2(){
        countFileDir("/Users/fuminwu/xxx/未命名文件夹");
        System.out.println(fileNum);
        System.out.println(dirNum);
    }
    @Test
    public void test(){
        File[] files = listDirFile("/Users/fuminwu/xxx");
        for (int i = 0; i < files.length; i++) {
            System.out.println(files[i].getName());
            System.out.println(files[i].getAbsolutePath());
        }
    }
    @Test
    public void test3(){
        File[] files = listDirFile("/Users/fuminwu/IdeaProjects/leetcode/src/main/java/com/wfm/leetcode/editor/cn");
        Arrays.sort(files);
        for (File file:files){
            System.out.println(file.getName());
        }
    }

}
